Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent errors when using ViewportTexture #75751

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Apr 6, 2023

setup_local_to_scene() is called right when the texture is initializing. It often fails on the first attempt, because the scene is not fully initialized and the assigned node path is still not valid. This PR ensures that ViewportTexture will only try to setup when the scene is prepared. Also there is no way to reasonably expect the texture to immediately hold correct data (size etc.), so I silenced the errors until the texture is initialized. It was already working correctly with the errors, so this PR just changes it to "intended behavior" and removes error spam.

Fixes #75740 and probably similar issues.

Ah I also had to add is_ready() method to Node, to reliably check if the node is ready. Maybe it could be exposed to scripting, because it's useful sometimes (although is_inside_tree() is enough in most cases).

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The change in control flow isn't a large as it appears from the size of the PR and overall it seems quite straightforward.

Copy link
Member

@mhilbrunner mhilbrunner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Node change likely needs a look by core?
Otherwise LGTM.

Comment on lines +2785 to +2791
bool Node::is_ready() const {
return !data.ready_first;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we expose this to the bindings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs a different name, because RichTextLabel already has is_ready() 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch... The RTL one should be named is_done_processing or similar... but that would break compat.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok exposed it as is_node_ready().

@KoBeWi KoBeWi force-pushed the eradicate_ViewportTexture_errors_entirely_and_surely branch from 40d8c9c to 1b9802f Compare May 8, 2023 13:56
@akien-mga akien-mga merged commit 15f9ac9 into godotengine:master May 8, 2023
@akien-mga
Copy link
Member

Thanks!

@snoopdouglas
Copy link
Contributor

snoopdouglas commented May 11, 2023

I note this has also fixed an (unticketed, to my knowledge) issue with a "proxy.is_valid()" is true error that would appear when using ViewportTextures in 4.0.2.

@akien-mga
Copy link
Member

Cherry-picked for 4.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use paths to reference SubViewport nodes
5 participants